package vn.com.pavibook.admin.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import vn.com.pavibook.dao.PublisherDao;
import vn.com.pavibook.dao.TransactionDao;
import vn.com.pavibook.domain.model.PagingInfo;
import vn.com.pavibook.domain.model.SearchResult;
import vn.com.pavibook.model.vo.TransactionVO;
import vn.com.pavibook.utils.DataHelper;

@Service
public class ManageTransactionService {
	
	@Autowired
	private PublisherDao publisherDao;
	
	@Autowired
	private TransactionDao transactionDao;
	
	public SearchResult<TransactionVO> getTransection(PagingInfo pagingInfo, String keyword, String typeStatistic, String username, String role, String typeSearch){
		int publisherId = 0;
		if(DataHelper.UserRole.ROLE_PUBLISHER.getCode().equals(role)){
			publisherId = publisherDao.getIdByUsername(username);
		}else if(DataHelper.UserRole.ROLE_FOR_ADMIN.getCode().equals(role)){
			publisherId = 0;
		}else{
			return new SearchResult<TransactionVO>();
		}
		
		return transactionDao.getTransection(pagingInfo, keyword, typeStatistic, publisherId, role, typeSearch);
	}

	public double getMoneyStatistic(String username, String role,
			String fromDate, String toDate) {
		int publisherId = 0;
		if(DataHelper.UserRole.ROLE_PUBLISHER.getCode().equals(role)){
			publisherId = publisherDao.getIdByUsername(username);
		}else if(DataHelper.UserRole.ROLE_FOR_ADMIN.getCode().equals(role)){
			publisherId = 0;
		}else{
			return 0;
		}
		return transactionDao.getMoneyStatistic(role, publisherId, fromDate, toDate);
	}
}
